from django.db import models
from apps.user_management.models import CustomUser  # 关联用户模块

class Schedule(models.Model):
    """班次信息模型"""
    departure = models.CharField('出发地', max_length=100)
    destination = models.CharField('目的地', max_length=100)
    departure_time = models.DateTimeField('发车时间')
    arrival_time = models.DateTimeField('到达时间')
    seats_total = models.IntegerField('总座位数')
    seats_available = models.IntegerField('可用座位数')
    price = models.DecimalField('票价', max_digits=8, decimal_places=2)
    created_by = models.ForeignKey(
        CustomUser, 
        on_delete=models.SET_NULL, 
        null=True, 
        verbose_name='创建人'
    )

    class Meta:
        verbose_name = '班次'
        verbose_name_plural = '班次管理'

    def __str__(self):
        return f"{self.departure} → {self.destination} ({self.departure_time})"